import { fetchGet, fetchPost } from './request';
import { getStore } from '@/config/mUtils';

/**
 * 获取首页默认地址
 */

export const cityGuess = () => fetchGet('/v1/cities', {
  type: 'guess'
});
/**
 * 获取热门城市
 */
export const getHotCity = () => fetchGet('/v1/cities', {
  type: 'hot'
});
/**
 * 获取所有城市
 */
export const getAllCity = () => fetchGet('/v1/cities', {
  type: 'group'
});


/**
 * 获取用户信息
 */

export const getUser =
  () => fetchGet('/v1/user', { user_id: getStore('user_id') });

/**
*个人中心里编辑地址
*/

export const getAddressList = (user_id) => fetchGet('/v1/users/' + user_id + '/addresses')

/* 获取图片验证码 */
export const getcaptchas = () => fetchPost('/v1/captchas', {})

/**
 * 账号密码登录
 */
export const accountLogin = (username, password, captcha_code) => fetchPost('/v2/login', { username, password, captcha_code });

/* 获取当前城市id */
export const currentCity = (cityid) => fetchGet('/v1/cities/' + cityid);

/* 搜索地址 */
export const searchplace = (cityid, inputVaule) => fetchGet('/v1/pois', {
  type: 'search',
  city_id: cityid,
  keyword: inputVaule
});
/* 获取msite页面地址信息 */
export const msiteAddress = geohash => fetchGet('/v2/pois/' + geohash);

/* 获取所有商铺分类列表 */
export const msiteFoodTypes = () => fetchGet('v2/index_entry');

/**
 * 获取msite商铺列表
 */
export const shopList = (latitude, longitude, offset, restaurant_category_id = '', restaurant_category_ids = '', order_by = '', delivery_mode = '', support_ids = []) => {
  let supportStr = '';
  support_ids.forEach(item => {
    if (item.status) {
      supportStr += '&support_ids[]=' + item.id;
    }
  });
  let data = {
    latitude,
    longitude,
    offset,
    limit: '20',
    'extras[]': 'activities',
    keyword: '',
    restaurant_category_id,
    'restaurant_category_ids[]': restaurant_category_ids,
    order_by,
    'delivery_mode[]': delivery_mode + supportStr
  };
  return fetchGet('/shopping/restaurants', data);
};
/**
 * 获取shop页面商铺详情
 */

export const shopDetails = (shopid, latitude, longitude) => fetchGet('/shopping/restaurant/' + shopid, {
  latitude,
  longitude: longitude + '&extras[]=activities&extras[]=album&extras[]=license&extras[]=identification&extras[]=statistics'
});

/**
 * 获取shop页面菜单列表
 */
export const foodMenu = restaurant_id => fetchGet('/shopping/v2/menu', { restaurant_id })

/* 获取店铺评论列表信息 */

export const getRatingList = (shopid, offset, tag_name = '') => fetchGet('/ugc/v2/restaurants/' + shopid + '/ratings', {
  has_content: true,
  offset,
  limit: 10,
  tag_name
})

/* 获取评价分数 */
export const ratingScores = restaurant_id => fetchGet('/ugc/v2/restaurants/' + restaurant_id + '/ratings/scores')

/**
 * 获取商铺评价分类
 */
export const ratingTags = restaurant_id => fetchGet('/ugc/v2/restaurants/' + restaurant_id + '/ratings/tags')
